package cx3k.GUI;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class ScheduledSemester implements Comparable<ScheduledSemester> { 
	
	public static final int NO_SEMESTER_ID = -1;
	public static final int NO_YEAR = 0;
	public static final String NO_TERM = "No term";
	
	private int semesterId;
	private int year;
	private String term;
	
	private Set<Course> courses = new HashSet<Course>();
	
	public ScheduledSemester(){
		this(NO_SEMESTER_ID, NO_YEAR, NO_TERM);
	}
	
	/*
	public ScheduledSemester(ScheduledSemester copy){
		this(copy.getSemesterId(), copy.getYear(), copy.getTerm());
		
		for(Course course : copy.getCourses()){
			this.addCourse(CopyUtil.deepCopyCourse(course));
		}
	}
	*/
	
	public ScheduledSemester(int semesterId){
		this(semesterId, NO_YEAR, NO_TERM);
	}
	
	public ScheduledSemester(int year, String term){
		this(NO_SEMESTER_ID, year, term);
	}
	
	public ScheduledSemester(int semesterId, int year, String term){
		setSemesterId(semesterId);
		setYear(year);
		setTerm(term);
	}
	
	public boolean addCourse(Course course){
		return courses.add(course);
	}
	
	public boolean addCourses(Collection<Course> courses){
		return getCourses().addAll(courses);
	}
	
	public Set<Course> getCourses(){
		return courses;
	}
	
	public int getSemesterId(){
		return semesterId;
	}
	
	public String getTerm(){
		return term;
	}
	
	public int getYear(){
		return year;
	}
	
	public boolean removeCourse(Course course){
		return courses.remove(course);
	}
	
	public void setCourses(Set<Course> courses){
		this.courses = courses;
	}
	
	public void setSemesterId(int semesterId){
		this.semesterId = semesterId;
	}
	
	public void setTerm(String term){
		this.term = term;
	}
	
	public void setYear(int year){
		this.year = year;
	}
	
	@Override
	public boolean equals(Object obj){
		try{
			ScheduledSemester other = (ScheduledSemester) obj;
			
			return this.getSemesterId() == other.getSemesterId() &&
				   this.getYear() == other.getYear() &&
				   this.getTerm() == other.getTerm();
			
		} catch(ClassCastException e){
			return false;
		}
	}

	@Override
	public int compareTo(ScheduledSemester other) {
		
		//int comparedYears = CompareUtil.compareYears(this.getYear(), other.getYear());
		
		/*
		if(comparedYears == 0){
			return CompareUtil.compareTerms(this.getTerm(), other.getTerm());
		} else {
			return comparedYears;
		}
		*/
		return 0;
	}
	
	
	
	
}
